import request from '@/utils/request'
// import qs from 'qs'

// IPsec_Vpn

// 获取ipsec_vpn列表
export function getArray (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/getArray',
    method: 'post',
    data
  })
}

// 获取信息
export function getInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/getInfo',
    method: 'post',
    data
  })
}

// 增加ipsec_vpn信息
export function addInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/addInfo',
    method: 'post',
    data
  })
}

// 增加本地网段信息
export function addLocalNetwork (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/addLocalNetwork',
    method: 'post',
    data
  })
}

// 增加远端网段信息
export function addRemoteNetwork (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/addRemoteNetwork',
    method: 'post',
    data
  })
}

// 隧道开启关闭
export function switchStatus (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/switch',
    method: 'post',
    data
  })
}

// 删除信息
export function del_info (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/del_info',
    method: 'post',
    data
  })
}

// 编辑ipsec_vpn信息
export function editInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/editInfo',
    method: 'post',
    data
  })
}

// 删除本地网段
export function delLocalNetwork (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/delLocalNetwork',
    method: 'post',
    data
  })
}

// 删除远端网段
export function delRemoteNetwork (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/delRemoteNetwork',
    method: 'post',
    data
  })
}

// 获取全局配置信息
export function getGlobalInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/getGlobalInfo',
    method: 'post',
    data
  })
}

// 设置全局信息
export function setGlobalInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ipsec_vpn/setGlobalInfo',
    method: 'post',
    data
  })
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
